/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VerifierCompareSettings.java
 *
 * Created on May 5, 2011, 2:49:47 PM
 */

package UserInterface;

import env.ComparisonSettings;
import javax.swing.JFileChooser;

/**
 *
 * @author Kyle
 */
public class VerifierCompareSettings extends javax.swing.JFrame {

    private ComparisonSettings compare;
    private Setting _father;
    int screen;
    /** Creates new form VerifierCompareSettings */
    public VerifierCompareSettings(Setting father) {
         screen = 1;
        compare = env.Parameters.verifierComparisonSettings;
        _father = father;
        initComponents();
        refresh();

       

        jButton_back.setEnabled(false);
        jPanel_CardLayout.removeAll();
        jPanel_CardLayout.add(jPanelOptions1, "1");
        jPanel_CardLayout.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jPanel_CardLayout = new javax.swing.JPanel();
        jPanelOptions1 = new javax.swing.JPanel();
        jButton_chooseFolder_goldStandard = new javax.swing.JButton();
        jLabel30 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel28 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel31 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jPanelOptions2 = new javax.swing.JPanel();
        jLabel32 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jButton_back = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel_CardLayout.setLayout(new java.awt.CardLayout());

        jButton_chooseFolder_goldStandard.setText("Browse...");
        jButton_chooseFolder_goldStandard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_chooseFolder_goldStandardActionPerformed(evt);
            }
        });

        jLabel30.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel30.setText("Comparison Settings");

        jLabel35.setText("Golden Standard Directory:");

        jTextField3.setEditable(false);
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });
        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField3KeyReleased(evt);
            }
        });

        jCheckBox2.setText("Verify that gold standard annotations exist in new files");
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jCheckBox3.setText("Verify that all annotations in new files exist in gold standard");
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jScrollPane2.setViewportView(jList1);

        jLabel28.setText("Markables to check Against:");

        jButton5.setText("Add");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Remove");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel31.setText("Markable:");

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOptions1Layout = new javax.swing.GroupLayout(jPanelOptions1);
        jPanelOptions1.setLayout(jPanelOptions1Layout);
        jPanelOptions1Layout.setHorizontalGroup(
            jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptions1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel30, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelOptions1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox2)
                            .addComponent(jCheckBox3)
                            .addGroup(jPanelOptions1Layout.createSequentialGroup()
                                .addComponent(jLabel35)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton_chooseFolder_goldStandard))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 499, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelOptions1Layout.createSequentialGroup()
                                    .addComponent(jLabel28)
                                    .addGap(365, 365, 365))
                                .addGroup(jPanelOptions1Layout.createSequentialGroup()
                                    .addComponent(jButton6)
                                    .addGap(24, 24, 24)
                                    .addComponent(jLabel31)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButton5))))))
                .addContainerGap(110, Short.MAX_VALUE))
        );
        jPanelOptions1Layout.setVerticalGroup(
            jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptions1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel30)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_chooseFolder_goldStandard))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel28)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptions1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6)
                    .addComponent(jLabel31)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5))
                .addGap(36, 36, 36)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox3)
                .addContainerGap(42, Short.MAX_VALUE))
        );

        jPanel_CardLayout.add(jPanelOptions1, "card5");

        jLabel32.setFont(new java.awt.Font("Segoe UI", 1, 14));
        jLabel32.setText("Specialized Verification Settings");

        jCheckBox1.setText("Check For Duplicates");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox4.setText("Check For Ghost Annotations");
        jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4ActionPerformed(evt);
            }
        });

        jCheckBox5.setText("Check For Spaces On Both Sides Of Annotations");
        jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox5ActionPerformed(evt);
            }
        });

        jCheckBox6.setText("Check For Only One Space Between Persons");
        jCheckBox6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOptions2Layout = new javax.swing.GroupLayout(jPanelOptions2);
        jPanelOptions2.setLayout(jPanelOptions2Layout);
        jPanelOptions2Layout.setHorizontalGroup(
            jPanelOptions2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptions2Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanelOptions2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox6)
                    .addComponent(jCheckBox5)
                    .addComponent(jCheckBox4)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel32, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(361, Short.MAX_VALUE))
        );
        jPanelOptions2Layout.setVerticalGroup(
            jPanelOptions2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptions2Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel32)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox6)
                .addContainerGap(206, Short.MAX_VALUE))
        );

        jPanel_CardLayout.add(jPanelOptions2, "card5");

        getContentPane().add(jPanel_CardLayout, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 380));

        jButton1.setText("Next");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 390, -1, -1));

        jButton_back.setText("Back");
        jButton_back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_backActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_back, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 390, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**user clicked button to launch a file chooser dialog to select
     * a folder which contains XML files of gold standard annotations
     * for subsequent verifyer processing.
     */
    private void jButton_chooseFolder_goldStandardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_chooseFolder_goldStandardActionPerformed
        
        // ####1 set the attributes of the dialog of file chooser before launching this dialog
        jFileChooser1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jFileChooser1.setDialogType(JFileChooser.OPEN_DIALOG);
        jFileChooser1.setMultiSelectionEnabled(false);
        jFileChooser1.setDialogTitle("Select the folder of you gold standard:");

        // ####2: launch the dialog and get the selected directory
        int re = jFileChooser1.showOpenDialog(this);

        //jLabel8.setText(String.valueOf(re));
        if (re == 0) {
            //jFileChooser1.setFileSelectionMode(1);
            String filename = jFileChooser1.getSelectedFile().getPath();
            compare.setDirectoryString(filename);
            refresh();
        }
}//GEN-LAST:event_jButton_chooseFolder_goldStandardActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        compare.setCheckExistsInNew(!compare.getCheckExistsInNew());
        refresh();
}//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
        compare.setCheckExistsInOld(!compare.getCheckExistsInOld());
        refresh();
}//GEN-LAST:event_jCheckBox3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        String markable = jTextField4.getText();
        jTextField4.setText("");
        if(markable.equals("")) {
            return;
        }
        compare.AddClass(markable);
        refresh();
}//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        Object[] selected = jList1.getSelectedValues();
        for(Object isSelected: selected) {
            compare.RemoveClass((String)isSelected);
        }
        refresh();
}//GEN-LAST:event_jButton6ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        switch(screen)
        {
            case (1):
                screen = 2;
                jButton_back.setEnabled(false);
                jPanel_CardLayout.removeAll();
                jPanel_CardLayout.add(jPanelOptions2, "2");
                jPanel_CardLayout.repaint();
                this.jButton_back.setEnabled(true);
                this.jButton1.setText("Done");
                break;

            case (2):
                config.project.ProjectConf projectconf = new config.project.ProjectConf(
                            env.Parameters.WorkSpace.CurrentProject);
                projectconf.saveConfigure();
                _father.setVisible(true);
                _father.setEnabled(true);
                this.dispose();
        }
        refresh();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        compare.setDirectoryString(jTextField3.getText());
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyReleased
        compare.setDirectoryString(jTextField3.getText());
        refresh();
    }//GEN-LAST:event_jTextField3KeyReleased

    private void jButton_backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_backActionPerformed
        jButton_back.setEnabled(false);
        screen = 1;

        jButton_back.setEnabled(false);
        jPanel_CardLayout.removeAll();
        jPanel_CardLayout.add(jPanelOptions1, "1");
        jPanel_CardLayout.repaint();
        this.jButton1.setText("Next");
    }//GEN-LAST:event_jButton_backActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        compare.setCheckDuplicates(!compare.getCheckDuplicates());
        refresh();
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
        compare.setSearchForGhosts(!compare.getSearchForGhosts());
        refresh();
    }//GEN-LAST:event_jCheckBox4ActionPerformed

    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
        compare.setCheckSpaceBothSides(!compare.getCheckSpaceBothSides());
        refresh();
    }//GEN-LAST:event_jCheckBox5ActionPerformed

    private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
        compare.setSearchForOneSpaceBetweenPersons(!compare.getSearchForOneSpaceBetweenPersons());
        refresh();
    }//GEN-LAST:event_jCheckBox6ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        this._father.setVisible(true);
        this._father.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        this._father.setVisible(true);
        this._father.setEnabled(true);
    }//GEN-LAST:event_formWindowClosed

    private void refresh()
    {
        if(screen == 1)
        {
            jTextField3.setText(compare.getDirectoryString());
            jList1.removeAll();
            jList1.setListData(compare.getComparisonClasses().toArray());
            jCheckBox2.setSelected(compare.getCheckExistsInNew());
            jCheckBox3.setSelected(compare.getCheckExistsInOld());
        }
        if(screen == 2)
        {
            jCheckBox1.setSelected(compare.getCheckDuplicates());
            jCheckBox4.setSelected(compare.getSearchForGhosts());
            jCheckBox5.setSelected(compare.getCheckSpaceBothSides());
            jCheckBox6.setSelected(compare.getSearchForOneSpaceBetweenPersons());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton_back;
    private javax.swing.JButton jButton_chooseFolder_goldStandard;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JCheckBox jCheckBox6;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanelOptions1;
    private javax.swing.JPanel jPanelOptions2;
    private javax.swing.JPanel jPanel_CardLayout;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables

}
